<?php
require_once ('View/Result.inc.php');
class ControllerLoader {
	public $module = '';
	private $pattern = '/[\/\\\.]/';
	public $Category = '';

	public function setCategory ($Category) {
		$this->Category = $Category;
	}

	public function execude () {
		if ($this->Category != '' && array_key_exists ('module', $_REQUEST) && !preg_match ($this->pattern, $_REQUEST['module']) && $this->checkController ($_REQUEST['module'])) {
			$this->module = $_REQUEST['module'];
		} else {
			$this->module = 'Default';
#			$Result = new Result ();
#			print $Result->Create ();
		}
		require_once (sprintf ('Controller/%s/%s.inc.php', $this->Category, $this->module));
		$Controller = new Controller ();
		$Controller->execude ();
	}

	public function checkController ($module) {
		$filename = sprintf ('lib/Controller/%s/%s.inc.php', $this->Category, $module);
		return file_exists ($filename);
	}
}
?>